package com.arcvideo.acsplayer.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import com.arcvideo.acsplayer.R;

public class PlayAgainView extends FrameLayout {

	private Context mContext = null;

	private ImageButton mControlPlayAgainButton = null;

	private boolean mbNeedPlayAgain = false;

	private PlayAgainControlInterface mPlayAgainControlInterface = null;

	/**
	 * 回调接口
	 *
	 * @author skl5250
	 *
	 */
	public interface PlayAgainControlInterface {
		public void clickPlayAgain();
	}

	/**
	 * 按键事件
	 */
	private OnClickListener mOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View view) {
			switch (view.getId()) {
				case R.id.play_again :
					mPlayAgainControlInterface.clickPlayAgain();
					break;
				default :
					break;
			}
		}
	};

	/**
	 * 构造函数
	 *
	 * @param context
	 */
	public PlayAgainView(Context context) {
		super(context);
		mContext = context;
	}

	/**
	 * 构造函数
	 *
	 * @param context
	 * @param attributeSet
	 */
	public PlayAgainView(Context context, AttributeSet attributeSet) {
		super(context, attributeSet);
		mContext = context;
	}

	/**
	 * 初始化
	 *
	 * @param playAgainControlInterface
	 */
	public void init(PlayAgainControlInterface playAgainControlInterface) {
		mPlayAgainControlInterface = playAgainControlInterface;
		LayoutInflater.from(mContext).inflate(R.layout.actionbar_play_again, this);

		initUI();
	}

	/**
	 * 初始化UI
	 */
	public void initUI() {
		mControlPlayAgainButton = (ImageButton) findViewById(R.id.play_again);
		mControlPlayAgainButton.setOnClickListener(mOnClickListener);
	}

	/**
	 * 显示
	 */
	public void show() {
		setVisibility(View.VISIBLE);
		setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.slide_bottom_in));
	}

	/**
	 * 隐藏
	 */
	public void hide() {
		setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.slide_bottom_out));
		setVisibility(View.INVISIBLE);
	}

	/**
	 * 设置再次播放状态
	 *
	 * @param isOn
	 */
	public void setPlayAgainState(boolean isOn) {
		mbNeedPlayAgain = isOn;
		if (mbNeedPlayAgain) {
			mControlPlayAgainButton.setVisibility(VISIBLE);
		} else {
			mControlPlayAgainButton.setVisibility(GONE);
		}
	}
}